<template>
  <div class="article-page">
    <div class="banner">
      <div class="container">
        <h1>{{ article.title }}</h1>
        <ArticleMeta :article="article" />
      </div>
    </div>

    <div class="container page">
      <div class="row article-content">
        <!-- eslint-disable -->
        <div class="col-md-12" v-html="article.body"></div>
      </div>

      <hr />

      <div class="article-actions">
        <ArticleMeta :article="article" />
      </div>

      <div class="row">
        <div class="col-xs-12 col-md-8 offset-md-2">
          <ArticleComment :slug="slug" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/*eslint-disable */
import { getArticle } from './api/index'
import Md from 'markdown-it'
import ArticleMeta from './components/ArticleMeta/'
import ArticleComment from './components/ArticleComment/'
export default {
  head() {
    return {
      title: `${this.article.title} -RealWorld`,
      meta: [
        {
          hid: 'description',
          name: 'description',
          content: this.article.description
        }
      ]
    }
  },
  components: {
    ArticleMeta,
    ArticleComment
  },
  async asyncData({
    isDev,
    route,
    store,
    env,
    params,
    query,
    req,
    res,
    redirect,
    error
  }) {
    const { data } = await getArticle(params.slug)
    console.log(data)
    let md = new Md()
    data.article.body = md.render(data.article.body)
    return {
      article: data.article,
      slug: params.slug
    }
  }
}
</script>

<style scoped></style>
